# import PySimpleGUI as sg
# from const import * 

# sg.theme('Dark Brown 1')

# layout=[
#     [
#     sg.Table(values=[['' for row in range(len(table_headers))]for col in range(6)],
#     headings=table_headers,
#                         enable_events=True,
#                         auto_size_columns=True,
#                         display_row_numbers=True,
#                         font='Courier 14',
#                         key='_table_',
#                         background_color='#1DB954',
#                         text_color='red',
#                         num_rows=20, alternating_row_color='blue'),]
#                         ]

# window = sg.Window('人员信息表', layout, font='Courier 12')
# event, values = window.read()
# print(event,values)



# import PySimpleGUI as sg

# sg.theme('Dark Blue 3')  # please make your windows colorful

# layout = [[sg.Text('Your typed chars appear here:'), sg.Text(size=(12,1), key='-OUTPUT-')],
#           [sg.Input(key='-IN-')],
#           [sg.Button('Show'), sg.Button('Exit')]]

# window = sg.Window('Window Title', layout)

# while True:  # Event Loop
#     event, values = window.read()       # can also be written as event, values = window()
#     print(event, values)
#     if event is None or event == 'Exit':
#         break
#     if event == 'Show':
#         # change the "output" element to be the value of "input" element
#         window['-OUTPUT-'].update(values['-IN-'])
#         # above line can also be written without the update specified
#         window['-OUTPUT-'](values['-IN-'])

# window.close()

# add save file demo
# import PySimpleGUI as sg

# layout = [[
#     sg.InputText(visible=False, enable_events=True, key='fig_path'),
#     sg.FileSaveAs(
#         key='fig_save'
#     )
# ]]
# window = sg.Window('Demo Application', layout, finalize=True)

# fig_canvas_agg = None
# while True:  # Event Loop
#     event, values = window.Read()
#     if (event == 'fig_path') and (values['fig_path'] != ''):
#         print('Saving to:', values['fig_path'])
#     if event is None:
#         break

# import PySimpleGUI as sg
# frame_layout = [
#                   [sg.T('Text inside of a frame')],
#                   [sg.CB('Check 1'), sg.CB('Check 2')],
#                ]
# layout = [
#           [sg.Frame('My Frame Title', frame_layout, font='Any 12', title_color='blue',border_width=0)],
#           [sg.Submit(), sg.Cancel()]
#          ]

# window = sg.Window('Frame with buttons', layout, font=("Helvetica", 12))
# while True:  # Event Loop
#     event, values = window.Read()
#     print(event, values)
#     if event is None:
#         break


# Example 1: resize window by pan
# import PySimpleGUI as sg
# col1 = sg.Col(
#     [
#         [sg.Text('col Row 11')],
#         [sg.Text('col Row 12')],
#         [sg.Text('col Row 13')]
#        ]
#  )

# col2 = sg.Col(
#     [
#         [sg.Text('col Row 21')],
#         [sg.Text('col Row 22')],
#         [sg.Text('col Row 23')]
#        ]
#  )

# layout =[
#     [
#             sg.Button('show',key='_show_'),
#             sg.Button('hidden',key='_hidden_')
#         ],
#     [
#         sg.Pane(
#             [col1 ], 
#             orientation='v', 
#             background_color=None, 
#             size=(160,160),
#             # visible=False,
#             relief=sg.RELIEF_RAISED,
#             key='_pan_',
#             border_width=0)
#         ]
# ]
# window = sg.Window('Frame with buttons', layout, font=("Helvetica", 12)).Finalize()

# p_x, p_y = window.Element('_pan_').get_size()
# w_x, w_y = window.Size

# while True:  # Event Loop
#     event, values = window.Read()
#     print(event, values)
    

#     if event is None:
#         break
#     if event == '_show_':
#         window.Element('_pan_').update(visible=True)
#         window.Size =  w_x, w_y
        
#     if event == '_hidden_':
#         window.Element('_pan_').update(visible=False)
#         window.Size =  w_x,w_y-p_y
#     print('win size:',window.Size)
#     print('pan size:',window.Element('_pan_').get_size())
 

    
#     window.Refresh()
#     window.Refresh()







# Example 2: resize window by column
import PySimpleGUI as sg
table_headers=['a','b','c']
layout=[
    [
            sg.Button('show',key='_show_'),
            sg.Button('hidden',key='_hidden_')
        ],
   [ sg.Column([[
                    sg.Table(values=[['' for row in range(len(table_headers))]for col in range(120)],
                            headings=table_headers,
                            enable_events=True,
                            auto_size_columns=False,
                            display_row_numbers=True,
                            key='_query_table_',
                            # background_color='#2c2825',
                            # alternating_row_color='brown',
                            # text_color='red',
                            # visible=False,
                            num_rows=10,
                            vertical_scroll_only=False,
                            hide_vertical_scroll=False
                            )
                    ]],
                    key='_colm_')]
]
window = sg.Window('Frame with buttons', layout, font=("Helvetica", 12)).Finalize()

# p_x, p_y = window.Element('_colm_').get_size()
w_x, w_y = window.Size

print('first win size:',window.Size)
print('first Column size:',window.Element('_colm_').get_size())
col_y_size =None

while True:  # Event Loop
    event, values = window.Read()
    print(event, values)
    
    if not col_y_size:
      _,  col_y_size= window.Element('_colm_').get_size()
    if event is None:
        break
    if event == '_show_':
        window.Element('_colm_').update(visible=True)
        window.Size =  w_x, w_y
        
    if event == '_hidden_':
        window.Element('_colm_').update(visible=False)
        print("minus:",w_y, col_y_size)
        window.Size =  w_x,w_y-col_y_size
    print('win size:',window.Size)
    print('Column size:',window.Element('_colm_').get_size())
 

    
    window.Refresh()
    window.Refresh()


# test code for openpyxl and pandas
'''

import openpyxl
wb = openpyxl.load_workbook(filename = 'new.xlsx')
ws = wb['Sheet1']
df=pd.DataFrame(ws.values)
df[df[0].str.contains('王',na=False)]

#set first row as collumn
df.columns = df.iloc[0]
'''